package picobot.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFileChooser;

/**
 * a class that performs a load skin action
 */
public class LoadSkinAction implements ActionListener {

	JFileChooser fc;
	PicobotUserInterface pui;

	/**
	 * the constructor for the LoadSkinAction class which takes a
	 * PicobotUserInterface
	 * 
	 * @param pui
	 *            is the PicobotUserInterface
	 */
	public LoadSkinAction(PicobotUserInterface pui) {
		this.pui = pui;
	}

	@Override
	public void actionPerformed(ActionEvent e) {

		fc = new JFileChooser();
		fc.setCurrentDirectory(new java.io.File("."));
		fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

		int returnVal = fc.showOpenDialog(fc);

		if (returnVal == JFileChooser.APPROVE_OPTION) {
			String path = fc.getSelectedFile().getPath();

			// the path of the selected file is used as the argument for the
			// changeSkin method of the PicoPanel of the PicobotUserInterface
			pui.getScreen().changeSkin(path + "/");
			// the panel is updated
			pui.getScreen().panelReset();

		}

	}

}